<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="com.webapp.model.Post, com.webapp.model.PostModel, java.util.List, com.webapp.model.CircleModel, com.webapp.model.Circle" %>
<% 
	List posts =  (List)session.getAttribute("Posts");
	System.out.print(posts);
	if(posts == null)
		response.sendRedirect("Error.jsp"); 
%>
<!-- include moo talk header file -->
<%@ include file="MooTalkHeader.jsp" %>
<style>
	#holderP { overflow:auto; width: 500px; margin: 0px auto 0px auto;}
	#content { width: 200px; float: left; padding: 10px; }
	#count { width: 200px; padding:10px; float:right;}
</style>
		<div id="site_content_text">
		<% 
				String x = request.getParameter("comment"); 
				if(x != null) {
					
					if(x.equals("added")) {
						%>
							<p style="color:red;">
								Comment Added!
							</p>
						<%
					}
					
					if(x.equals("added")) {
						%>
							<p style="color:red;">
								Your fence was built! Please have a great day!
							</p>
						<%
					}
					
					if(x.equals("deleted")) {
						%>
							<p style="color:red;">
								Your fence was removed!
							</p>
						<%
					}
				}
			%>
			<h2>Barnyard</h2>
			
			<% for ( int i = 0; i < posts.size(); i++) { %>
			<% Post post = (Post)posts.get(i);%>
			<!--  grid type layout -->
			<% if ( i % 2 == 0) { %>
			<div class="even">
			<% } else if( i%2 == 1) { %>
			<div class="odd">
			<% } %>
				<div id="postOrComment">
	
					<div id="holderP">
						<div id="content">
							<p><%=post.getContent()%></p>
						</div>
		
						<div id="count">
						<% CircleModel cm = new CircleModel();
								Circle postcircle = cm.getCircle(post.getCircle());
								System.out.println("POST CRICLE" + postcircle);
								PostModel pm = new PostModel();
							%>
							<strong>+<%=pm.numberOfLikes(post.getPostId())%></strong><br/>
							<strong>Date:</strong><br/><%=post.getDate()%><br/>
							<strong>Author:</strong><br/> <%=post.getAuthor()%><br/>
							<strong>Circle Name: </strong><br/><%=postcircle.getCircleName()%><br/>
							<strong>Circle Type: </strong><br/><%=postcircle.getCircleType()%>
							
						</div>
					</div>
					
					<div id="navigation">
							<% 
							User theUser = (User) user;
							if ( theUser.getUserId() == post.getAuthor()) { %>
								<form action="EditPost.do" method="post">
									<input type="hidden" name="POSTID" value="<%=post.getPostId()%>" />
									<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
									<input type="hidden" name="CIRCLEID" value="<%=postcircle.getCircleId()%>" />
									<textarea rows="4" cols="20 " name="POSTTXT"><%=post.getContent()%></textarea><br/>
									<input class="btn" type="submit" value="Edit Moo!"/>
								</form>
						<% } %>
						<form action="Like.do" method="post">
							<input type="hidden" name="POSTID" value="<%=post.getPostId()%>" />
							<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
							<input class="btn" type="submit" value="Like Moo!"/>
						</form>
						
						<form action="Dislike.do" method="post">
							<input type="hidden" name="POSTID" value="<%=post.getPostId()%>" />
							<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
							<input class="btn" type="submit" value="Dislike Moo!"/>
						</form>
						<form action="CommentPost.do" method="post">
							<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
							<input type="hidden" name="POSTID" value="<%=post.getPostId()%>" />
							<textarea rows="4" cols="20" name="COMMENTTXT"></textarea><br/>
							<input class="btn" type="submit" value="Comment this Moo!"/>
						</form>
						<form action="ViewComments.do" method="post">
							<input type="hidden" name="POSTID" value="<%=post.getPostId()%>" />
							<input class="btn" type="submit" value="View Moo's Comments!"/>
						</form>
						<% 
							if ( theUser.getUserId() == post.getAuthor()) { %>
								<form action="DeletePost.do" method="post">
									<input type="hidden" name="USERID" value="<%=myUser.getUserId()%>" />
									
									<input type="hidden" name="POSTID" value="<%=post.getPostId()%>" />
									<input class="btn" type="submit" value="Remove Post!"/>
								</form>
						<% } %>
						
					</div>
				</div>	
			</div>
			<% } %>
		</div>
		
<!--  include moo talk footer file -->
<%@ include file="MooTalkFooter.jsp" %>
